package moe.codeest.enviews;

import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.CornerPathEffect;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PathMeasure;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.view.animation.AnticipateInterpolator;
import com.shuyu.gsyvideoplayer.R;

/* loaded from: classes2.dex */
public class ENPlayView extends View {
    public static int DEFAULT_BG_LINE_COLOR = -328966;
    public static int DEFAULT_BG_LINE_WIDTH = 4;
    public static int DEFAULT_DURATION = 1200;
    public static int DEFAULT_LINE_COLOR = -1;
    public static int DEFAULT_LINE_WIDTH = 4;
    public static int STATE_PAUSE = 1;
    public static int STATE_PLAY;
    private Paint mBgPaint;
    private RectF mBgRectF;
    private int mCenterX;
    private int mCenterY;
    private int mCircleRadius;
    private int mCurrentState;
    private Path mDstPath;
    private int mDuration;
    private float mFraction;
    private int mHeight;
    private Paint mPaint;
    private Path mPath;
    private float mPathLength;
    private PathMeasure mPathMeasure;
    private RectF mRectF;
    private int mWidth;

    public ENPlayView(Context context) {
        super(context);
        this.mCurrentState = STATE_PAUSE;
        this.mFraction = 1.0f;
    }

    public ENPlayView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.mCurrentState = STATE_PAUSE;
        this.mFraction = 1.0f;
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.play);
        int color = obtainStyledAttributes.getColor(R.styleable.play_play_line_color, DEFAULT_LINE_COLOR);
        int color2 = obtainStyledAttributes.getColor(R.styleable.play_play_bg_line_color, DEFAULT_BG_LINE_COLOR);
        int integer = obtainStyledAttributes.getInteger(R.styleable.play_play_line_width, dp2px(DEFAULT_LINE_WIDTH));
        int integer2 = obtainStyledAttributes.getInteger(R.styleable.play_play_bg_line_width, dp2px(DEFAULT_BG_LINE_WIDTH));
        obtainStyledAttributes.recycle();
        setLayerType(1, null);
        this.mPaint = new Paint(1);
        this.mPaint.setStyle(Paint.Style.STROKE);
        this.mPaint.setStrokeCap(Paint.Cap.ROUND);
        this.mPaint.setColor(color);
        this.mPaint.setStrokeWidth(integer);
        this.mPaint.setPathEffect(new CornerPathEffect(1.0f));
        this.mBgPaint = new Paint(1);
        this.mBgPaint.setStyle(Paint.Style.STROKE);
        this.mBgPaint.setStrokeCap(Paint.Cap.ROUND);
        this.mBgPaint.setColor(color2);
        this.mBgPaint.setStrokeWidth(integer2);
        this.mPath = new Path();
        this.mDstPath = new Path();
        this.mPathMeasure = new PathMeasure();
        this.mDuration = DEFAULT_DURATION;
    }

    @Override // android.view.View
    protected void onSizeChanged(int i, int i2, int i3, int i4) {
        super.onSizeChanged(i, i2, i3, i4);
        this.mWidth = (i * 9) / 10;
        this.mHeight = (i2 * 9) / 10;
        this.mCircleRadius = this.mWidth / dp2px(4);
        this.mCenterX = i / 2;
        this.mCenterY = i2 / 2;
        int i5 = this.mCenterX;
        int i6 = this.mCircleRadius;
        int i7 = this.mCenterY;
        this.mRectF = new RectF(i5 - i6, i7 + (i6 * 0.6f), i5 + i6, i7 + (i6 * 2.6f));
        int i8 = this.mCenterX;
        int i9 = this.mWidth;
        int i10 = this.mCenterY;
        int i11 = this.mHeight;
        this.mBgRectF = new RectF(i8 - (i9 / 2), i10 - (i11 / 2), i8 + (i9 / 2), i10 + (i11 / 2));
        Path path = this.mPath;
        int i12 = this.mCenterX;
        int i13 = this.mCircleRadius;
        path.moveTo(i12 - i13, this.mCenterY + (i13 * 1.8f));
        Path path2 = this.mPath;
        int i14 = this.mCenterX;
        int i15 = this.mCircleRadius;
        path2.lineTo(i14 - i15, this.mCenterY - (i15 * 1.8f));
        this.mPath.lineTo(this.mCenterX + this.mCircleRadius, this.mCenterY);
        this.mPath.close();
        this.mPathMeasure.setPath(this.mPath, false);
        this.mPathLength = this.mPathMeasure.getLength();
    }

    @Override // android.view.View
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawCircle(this.mCenterX, this.mCenterY, this.mWidth / 2, this.mBgPaint);
        float f = this.mFraction;
        if (f < 0.0f) {
            int i = this.mCenterX;
            int i2 = this.mCircleRadius;
            int i3 = this.mCenterY;
            canvas.drawLine(i + i2, (i3 - (i2 * 1.6f)) + (i2 * 10 * f), i + i2, i3 + (i2 * 1.6f) + (i2 * 10 * f), this.mPaint);
            int i4 = this.mCenterX;
            int i5 = this.mCircleRadius;
            int i6 = this.mCenterY;
            canvas.drawLine(i4 - i5, i6 - (i5 * 1.6f), i4 - i5, i6 + (i5 * 1.6f), this.mPaint);
            canvas.drawArc(this.mBgRectF, -105.0f, 360.0f, false, this.mPaint);
        } else if (f <= 0.3d) {
            int i7 = this.mCenterX;
            int i8 = this.mCircleRadius;
            int i9 = this.mCenterY;
            canvas.drawLine(i7 + i8, (i9 - (i8 * 1.6f)) + (((i8 * 3.2f) / 0.3f) * f), i7 + i8, i9 + (i8 * 1.6f), this.mPaint);
            int i10 = this.mCenterX;
            int i11 = this.mCircleRadius;
            int i12 = this.mCenterY;
            canvas.drawLine(i10 - i11, i12 - (i11 * 1.6f), i10 - i11, i12 + (i11 * 1.6f), this.mPaint);
            float f2 = this.mFraction;
            if (f2 != 0.0f) {
                canvas.drawArc(this.mRectF, 0.0f, f2 * 600.0f, false, this.mPaint);
            }
            RectF rectF = this.mBgRectF;
            float f3 = this.mFraction;
            canvas.drawArc(rectF, (f3 * 360.0f) - 105.0f, (1.0f - f3) * 360.0f, false, this.mPaint);
        } else if (f <= 0.6d) {
            canvas.drawArc(this.mRectF, (f - 0.3f) * 600.0f, 180.0f - ((f - 0.3f) * 600.0f), false, this.mPaint);
            this.mDstPath.reset();
            PathMeasure pathMeasure = this.mPathMeasure;
            float f4 = this.mPathLength;
            pathMeasure.getSegment(0.02f * f4, (0.38f * f4) + (((f4 * 0.42f) / 0.3f) * (this.mFraction - 0.3f)), this.mDstPath, true);
            canvas.drawPath(this.mDstPath, this.mPaint);
            RectF rectF2 = this.mBgRectF;
            float f5 = this.mFraction;
            canvas.drawArc(rectF2, (f5 * 360.0f) - 105.0f, (1.0f - f5) * 360.0f, false, this.mPaint);
        } else if (f <= 0.8d) {
            this.mDstPath.reset();
            PathMeasure pathMeasure2 = this.mPathMeasure;
            float f6 = this.mPathLength;
            float f7 = this.mFraction;
            pathMeasure2.getSegment((0.02f * f6) + (((f6 * 0.2f) / 0.2f) * (f7 - 0.6f)), (0.8f * f6) + (((f6 * 0.2f) / 0.2f) * (f7 - 0.6f)), this.mDstPath, true);
            canvas.drawPath(this.mDstPath, this.mPaint);
            RectF rectF3 = this.mBgRectF;
            float f8 = this.mFraction;
            canvas.drawArc(rectF3, (f8 * 360.0f) - 105.0f, (1.0f - f8) * 360.0f, false, this.mPaint);
        } else {
            this.mDstPath.reset();
            this.mPathMeasure.getSegment(this.mCircleRadius * 10 * (this.mFraction - 1.0f), this.mPathLength, this.mDstPath, true);
            canvas.drawPath(this.mDstPath, this.mPaint);
        }
    }

    public void play() {
        int i = this.mCurrentState;
        int i2 = STATE_PLAY;
        if (i == i2) {
            return;
        }
        this.mCurrentState = i2;
        ValueAnimator ofFloat = ValueAnimator.ofFloat(1.0f, 100.0f);
        ofFloat.setDuration(this.mDuration);
        ofFloat.setInterpolator(new AnticipateInterpolator());
        ofFloat.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { // from class: moe.codeest.enviews.ENPlayView.1
            @Override // android.animation.ValueAnimator.AnimatorUpdateListener
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                ENPlayView.this.mFraction = 1.0f - valueAnimator.getAnimatedFraction();
                ENPlayView.this.invalidate();
            }
        });
        if (ofFloat.isRunning()) {
            return;
        }
        ofFloat.start();
    }

    public void pause() {
        int i = this.mCurrentState;
        int i2 = STATE_PAUSE;
        if (i == i2) {
            return;
        }
        this.mCurrentState = i2;
        ValueAnimator ofFloat = ValueAnimator.ofFloat(1.0f, 100.0f);
        ofFloat.setDuration(this.mDuration);
        ofFloat.setInterpolator(new AnticipateInterpolator());
        ofFloat.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { // from class: moe.codeest.enviews.ENPlayView.2
            @Override // android.animation.ValueAnimator.AnimatorUpdateListener
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                ENPlayView.this.mFraction = valueAnimator.getAnimatedFraction();
                ENPlayView.this.invalidate();
            }
        });
        if (ofFloat.isRunning()) {
            return;
        }
        ofFloat.start();
    }

    public int getCurrentState() {
        return this.mCurrentState;
    }

    public void setDuration(int i) {
        this.mDuration = i;
    }

    private int dp2px(int i) {
        return (int) TypedValue.applyDimension(1, i, getContext().getResources().getDisplayMetrics());
    }
}
